# Maintainer: Felix Yan <felixonmars@archlinux.org>

pkgname=ruby-range_compressor
pkgver=1.2.0
pkgrel=1
pkgdesc='Compresses Arrays of Objects to Arrays of Ranges'
arch=(any)
url='https://github.com/jaynetics/range_compressor'
license=(MIT)
depends=(ruby)
checkdepends=(ruby-rake ruby-rspec ruby-sorted_set)
options=(!emptydirs)
source=(https://github.com/jaynetics/range_compressor/archive/v$pkgver/$pkgname-$pkgver.tar.gz)
sha256sums=('0b1544ce2e3980495f11e6e26c248c30c9246c840f5f6ccca5634fd320e4201d')

prepare() {
  cd range_compressor-$pkgver
  sed -i -r -e 's|git ls-files -z|find . -type f -not -path "*/\.git/*" -not -path "*\.gem" -printf "%P\\\\0"|' range_compressor.gemspec
}

build() {
  local _gemdir="$(gem env gemdir)"
  cd range_compressor-$pkgver
  gem build range_compressor.gemspec
  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$_gemdir" \
    --bindir "tmp_install/usr/bin" \
    range_compressor-$pkgver.gem
  find "tmp_install/$_gemdir/gems/" \
    -type f \
    \( \
        -iname "*.o" -o \
        -iname "*.c" -o \
        -iname "*.so" -o \
        -iname "*.time" -o \
        -iname "gem.build_complete" -o \
        -iname "Makefile" \
    \) \
    -delete
  rm -r tmp_install/$_gemdir/cache
}

check() {
  local _gemdir="$(gem env gemdir)"
  cd range_compressor-$pkgver
  GEM_HOME="tmp_install/$_gemdir" rake
}

package() {
  cd range_compressor-$pkgver
  cp -a tmp_install/* "$pkgdir"/
  install -Dm644 LICENSE.txt -t "$pkgdir"/usr/share/licenses/$pkgname/
}
